class Cookie{
    constructor(){

    }
    cookie(name,value,json){
        //初始化json
        json = json || {};
        //主键值对
        let cookie_str = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
        //有效期
        if(!isNaN(json.expires)){
            let date = new Date();
            date.setDate(date.getDate() + json.expires);
            cookie_str += `;expires=${date}`;
        }
        //路径
        if(json.path){
            cookie_str += `;path=${json.path}`;
        }
        //域名
        if(json.domain){
            cookie_str += `;domain=${json.domain}`;
        }
        //安全（https)
        if(json.secure){
            cookie_str += ';secure';
        }
        //创建cookie
        document.cookie = cookie_str;
    }
    getCookie(name){
        name = encodeURIComponent(name);
        let arr = document.cookie.split('; ');
        for(let i = 0,len = arr.length;i < len;i ++){
            let list = arr[i].split('=');
            if(list[0] === name){
                return decodeURIComponent(list[1]);
            }
        }
    }
    removeCookie(name,json){
        json = json || {};
        if(json.path){
            document.cookie = `${encodeURIComponent(name)}=;path=${json.path};expires=${new Date(0)}`;
        }else{
            document.cookie = `${encodeURIComponent(name)}=;expires=${new Date(0)}`;
        }
    }
}